<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    
</body>
<script>
    // 多态 => 通过不同类创建的实例化对象,在调用同一个方法会展示不同的结果

    // JS默认是无态的 => 天生就支持多态


    class Cat{
        constructor(name,age){
            this.name = name;
            this.age = age;
        }
        call(){
            console.log("喵喵");
        }
    }

    class Dog{
        constructor(name,age){
            this.name = name;
            this.age = age;
        }
        call(){
            console.log("旺旺");
        }
    }

    class Pig{
        constructor(name,age){
            this.name = name;
            this.age = age;
        }
        call(){
            console.log("哼哼");
        }
    }

    var Tom = new Cat("Tom",2);
    var WangCai = new Dog("WangCai",3);
    var PeiQi = new Pig("PeiQi",3);


    function animalCall(animal){
        animal.call();  // 重要的是 => 传入的对象是否有call方法,不是说一定要是哪个构造函数创建的
    }

    animalCall(Tom);
    animalCall(WangCai);
    animalCall(PeiQi);
    animalCall({
        call(){
            console.log("嘿嘿");
        }
    });
    

    





</script>
</html>